package com.sqx.config;

import com.jfinal.weixin.sdk.api.ApiConfig;
import com.jfinal.wxaapp.WxaConfig;
import com.sqx.modules.common.service.CommonInfoService;
import net.dreamlu.weixin.config.WxConfigLoader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;
import java.util.List;

@Configuration
public class WxConfigDatabaseConfig implements WxConfigLoader {

    @Autowired
    private CommonInfoService commonInfoService;

    @Override
    public List<ApiConfig> loadWx() {
        String appId = commonInfoService.findOne(5).getValue();
        String token = commonInfoService.findOne(16).getValue();
        String appSecret = commonInfoService.findOne(21).getValue();
        String encodingAesKey = commonInfoService.findOne(17).getValue();
        // 公众号
        ApiConfig wxConf = new ApiConfig();
        wxConf.setAppId(appId);
        wxConf.setAppSecret(appSecret);
        wxConf.setToken(token);
        wxConf.setEncryptMessage(false);
        wxConf.setEncodingAesKey(encodingAesKey);
        return Collections.singletonList(wxConf);
    }

    @Override
    public List<WxaConfig> loadWxa() {
        // 小程序
//        WxaConfig wxaConfig = new WxaConfig();
//        //参数
//        return Collections.singletonList(wxaConfig);
        return Collections.emptyList();
    }
}